﻿using common.consolecomponents;
using common.helpers;
using webserver.core;

var port = RandomHelper.Instance.Next(5000, 9999);
TaskHelper.RunUseThread(() =>
{
    Init(port);
});

var url = $"http://localhost:{port}";
ProcessStart.Run(url);

Console.WriteLine(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
Console.WriteLine($"服务已启动，{url}");
Console.WriteLine("-----------------------------------------------");
Console.WriteLine("按任意键退出");
Console.ReadKey();

void Init(int port)
{
    var option = new StartOption
    {
        Assembly = "bookmark.mgr.dll",
        BufferSize = 1024 * 1024,
        Error404Page = "/404.html",
        IndexPage = "/index.html",
        Port = port,
        Routes = new List<RouteItem>(),
        StaticFileExtensions = new Dictionary<string, string>()
    };

    InitRoutes(option);

    var server = new Server(option);
    server.Start();
}

void InitRoutes(StartOption option)
{
    option.Routes.Add(new RouteItem
    {
        Level = 0,
        NS = "bookmark.mgr.Controllers.Lv0"
    });
}